#include "RectApp.h"
#include <conio.h>

//constructor
RectApp::RectApp()
{
	m_isDefaultFull = true; //default value - full rectangles
	init();
}

//initializes the menus for the rectangle application
void RectApp::init()
{
	//main menu initialize
	m_menu.init(9);
	m_menu.set(0, "Add a rectangle (to a max 10 rectangles)");
	if (m_isDefaultFull)
	{
		m_menu.set(1, "Draw full rectangles");
		m_menu.set(2, "Change default to drawing empty rectangles");
	}
	else
	{
		m_menu.set(1, "Draw empty rectangles");
		m_menu.set(2, "Change default to drawing full rectangles");
	}
	m_menu.set(3, "Choose a rectangle, specify X and Y coordinates separated by a space");
	m_menu.set(4, "For future use");
	m_menu.set(5, "For future use");
	m_menu.set(6, "For future use");
	m_menu.set(7, "For future use");
	m_menu.set(8, "Exit");
	//sub menu initialize
	m_subMenu.init(5);
	m_subMenu.set(0, "Return to main menu");
	m_subMenu.set(1, "Delete selected rectangle");
	m_subMenu.set(2, "Send selected rectangle to front");
	m_subMenu.set(3, "Send selected rectangle to background");
	m_subMenu.set(4, "Shift selected rectangle");
}

void RectApp::addRect()
{
	Point point;
	int x, y, length, width;

	cout << "Please enter a rectangle point - X Y: " << endl;
	cin >> x;
	cin >> y;
	cout << "Please enter the rectangle length and width - must be natural numbers: " << endl;
	cin >> length;
	cin >> width;
	while (length < 0 && width < 0)
	{
		cout << "Invalid values! please enter only natural numbers for length and width" << endl;
		cout << "press any key to return the main menu" << endl;
		getch();
		cout << "Please enter the rectangle length and width - must be natural numbers: " << endl;
		cin >> length;
		cin >> width;
	}
	point.setPoint(x, y);
	m_rectCont.addRect(point, length,  width);
}

void RectApp::changeRectType()
{
	m_isDefaultFull = !m_isDefaultFull;
	if (m_isDefaultFull)
	{
		m_menu.set(1, "Draw full rectangles");
		m_menu.set(2, "Change default to drawing empty rectangles");
	}
	else
	{
		m_menu.set(1, "Draw empty rectangles");
		m_menu.set(2, "Change default to drawing full rectangles");
	}
}

void RectApp::subMenu()
{
	clrscr();
	m_subMenu.printMenu();

	getch();
}

//runs the application
void RectApp::runRectApp()
{
	bool shouldExit = false;
	unsigned int choice = NULL;

	while (!shouldExit)
	{
		clrscr();
		m_menu.printMenu();	//prints the main menu
		choice = m_menu.getChoice();
		cout << endl;
		switch (choice)
		{
			case 1: // add Rectangle
				addRect();
				m_rectCont.drawAll('*', m_isDefaultFull);
				break;
			case 2: // draw all Rectangles
				m_rectCont.drawAll('*', m_isDefaultFull);
				break;
			case 3: // change Default Type
				changeRectType();
				break;
			case 4: // enter Sub - Menu
				subMenu();
				break;
			case 9: //exit
				shouldExit = true;
				break;
			default:	//for the futue options: 5-8
				cout << "This option is for future use, please choose another option!" << endl;
				getch();
				break;
		}
		if (choice < 3)
		{
			gotoxy(1, 25); //go to the last line of the screen
			cout << "press any key to return the main menu" << endl;
			getch();
		}
	}
	cout << endl << endl;
}

//empty copy constructor
RectApp::RectApp(const RectApp& rectApp)
{
}

//empty destructor
RectApp::~RectApp()
{
}


